package com.he.demo.config;

import com.he.demo.service.hello.HelloService;
import com.he.demo.service.yyt.YytService;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import javax.xml.ws.Endpoint;

/**
 * @author heyanjing
 * date:2021-02-22 2021/2/22 0022:16:57
 */
@Configuration
public class CxfConfig {
    @Resource
    private Bus          springBus;

    @Resource
    private HelloService helloService;
    @Resource
    private YytService   yytService;

    /**
     *也可以不设置此bean 直接通过配置项 cxf.path 来修改访问路径的
     */
    //@Bean
    //public ServletRegistrationBean<CXFServlet> cxfServlet() {
    //    return new ServletRegistrationBean<>(new CXFServlet(), "/cxf/*");
    //}
    /**
     *META-INF/cxf/cxf.xml 中已经定义了 名为cxf的 SpringBus bean
     */
    //@Bean(name = Bus.DEFAULT_BUS_ID)
    //public SpringBus springBus() {
    //    return new SpringBus();
    //}

    @Bean
    public Endpoint hello() {
        EndpointImpl endpoint = new EndpointImpl(springBus, helloService);
        //EndpointImpl endpoint = new EndpointImpl(bus, helloService);//这种方式也可以
        endpoint.publish("/hello");
        return endpoint;
    }

    @Bean
    public Endpoint yyt() {
        EndpointImpl endpoint = new EndpointImpl(springBus, yytService);
        //EndpointImpl endpoint = new EndpointImpl(bus, helloService);//这种方式也可以
        endpoint.publish("/yyt");
        return endpoint;
    }


}
